// $Id: UIUtils.java 83 2012-01-19 14:45:27Z huijzer@gmail.com $
package lime.common;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.PlatformUI;

public class UIUtils {

	public static void refreshSelectionProvider(ISelectionProvider selectionProvider) {
		ISelection selection = selectionProvider.getSelection();
		if (selection != null) {
			selectionProvider.setSelection(null);
			selectionProvider.setSelection(selection);
		}
	}

	public static void clear(Composite composite) {
		for (Control control : composite.getChildren()) {
			control.dispose();
		}
	}

	public static String[][] getPerspectives() {

		IPerspectiveDescriptor[] descriptors = PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives();
		String[][] perspectives = new String[descriptors.length][2];

		for (int i = 0; i < descriptors.length; i++) {
			IPerspectiveDescriptor descriptor = descriptors[i];
			perspectives[i][0] = descriptor.getLabel();
			perspectives[i][1] = descriptor.getId();
		}

		return perspectives;
	}
}
